import { QXEvent } from "qx-util";
import { IParam, TreeActionType, ITreeAbility, ITreeControllerParams, ITreeStore, TreeController, ICtrlEvent, ITreeController, ITreeModel, ControlVOBase, } from "@/core";
import { useTreeAction, useTreeBasic, useTreeControllerParams, useTreeProps } from "@/hooks/widget/use-tree";
import { TreeControlVO } from './usr-tree-vo';
import { model } from "./usr-tree-model";
import TreeService from "@/core/modules/ctrl-service/tree-service";
// 基于template/src/widgets/{{appEntities}}/{{ctrls@TREEVIEW}}-tree/{{spinalCase ctrl.codeName}}-tree-hook.ts.hbs生成
/**
 * 获取输入参数
 *
 * @export
 * @return {*}
 */
export function useProps() {
	return {
		...useTreeProps(),
	};
}

/**
 * 获取基础数据
 *
 * @export
 * @param {*} props
 * @return {*}
 */
export function useBasic(props: any) {
	return {
		...useTreeBasic(model, props),
	};
}

/**
 * 获取行为
 *
 * @export
 */
export function useAction(controller: any) {
	return {
		...useTreeAction(controller),
	};
}

/**
 * 获取控制器
 *
 * @export
 * @param {IParam} props
 * @param {QXEvent<ICtrlEvent<TreeActionType, ITreeAbility>>} evt
 * @return {*}
 */
export function useController(
	props: IParam,
	evt: QXEvent<ICtrlEvent<TreeActionType, ITreeAbility>>,
    otherParams: IParam = {},
): ITreeController<ITreeStore, ITreeAbility> {
	const params: ITreeControllerParams<TreeActionType, ITreeAbility> =
		useTreeControllerParams<ITreeStore, ITreeModel>(model, props, evt, otherParams);
    const ctrlService = new TreeService<ControlVOBase[]>(TreeControlVO, model.entityCodeName, { model });
  	Object.assign(params, { ctrlService });
  	return new TreeController(params);
}